<?php

namespace App\Http\Controllers;

use App\Logic\ActivityLogic;
use Illuminate\Support\Facades\DB;

/**
 * SignIn 签到
 */
class SignIn extends Base
{

    /**
     * @return string
     * @throws \App\Exceptions\ApiException
     */
    public function logic()
    {

        $uid    = $this->uid;
        $object = DB::select("SELECT * FROM t_signin_rec where uid = $uid AND TO_DAYS(create_time) = TO_DAYS(NOW()) LIMIT 0,1;");
        if (count($object) >= 1) {
            return $this->returnError(1, "你今天已经签到了.");
        }
        $m_day = date("d");
        if (($object = ActivityLogic::instance()->activityConfInfo(2))) {
            $data = ActivityLogic::instance()->analysisHandle($object->rule, $uid, $object->name);
        }
        DB::table('t_signin_rec')->insert(["uid" => $uid, "day" => $m_day]);
        return $this->returnData([
            'add_gold' => $data['gold'] ?? 0,
            'add_diamond' =>$data['diamond'] ?? 0,
            'add_quickly_grab_ticket' => $data['quickly_grab_ticket'] ?? 0,
            'add_room_card' => $data['room_card'] ?? 0,
        ]);
    }

}